package com.zf.websocket.controller;

import com.zf.websocket.endpoint.PushEndpoint;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @author Zhou Feng
 */
@RestController
@RequestMapping("/push")
public class PushController {

    @GetMapping("/{userId}")
    public void push(@PathVariable("userId") String userId) throws IOException {
        PushEndpoint.sendInfo(String.format("%s 你好，我是服务器！", userId), userId);
    }

    @GetMapping("/all")
    public void pushAll() throws IOException {
        PushEndpoint.broadcast("广播消息");
    }
}
